<script setup>
import { inject } from 'vue';

const fileStore = inject('fileStore');
</script>

<template>
  <div class="upload-area">
    <el-upload
      class="upload-dragger"
      drag
      :multiple="
        fileStore.selectedFunction !== 'split_by_header' &&
        fileStore.selectedFunction !== 'sample_meter_list' &&
        fileStore.selectedFunction !== 'split_by_header_enhanced' &&
        fileStore.selectedFunction !== 'sample_data' &&
        fileStore.selectedFunction !== 'budget_calculation'
      "
      :auto-upload="false"
      :file-list="fileStore.fileList"
      :on-change="(file, files) => fileStore.updateFileList(files)"
      :on-remove="(file) => fileStore.removeFile(file)"
      accept=".xlsx,.xls"
      :limit="
        fileStore.selectedFunction === 'split_by_header' ||
        fileStore.selectedFunction === 'sample_meter_list' ||
        fileStore.selectedFunction === 'split_by_header_enhanced' ||
        fileStore.selectedFunction === 'sample_data' ||
        fileStore.selectedFunction === 'budget_calculation'
          ? 1
          : undefined
      "
    >
      <div class="upload-content">
        <i-ep-UploadFilled class="upload-icon" />
        <div class="upload-text">
          <template
            v-if="
              fileStore.selectedFunction === 'split_by_header' ||
              fileStore.selectedFunction === 'split_by_header_enhanced'
            "
          >
            上传要拆分的 Excel 文件（单个），或拖拽到此
          </template>
          <template
            v-else-if="
              fileStore.selectedFunction === 'sample_meter_list' ||
              fileStore.selectedFunction === 'sample_data'
            "
          >
            上传数据文件（单个），或拖拽到此
          </template>
          <template v-else-if="fileStore.selectedFunction === 'budget_calculation'">
            上传预算模板文件（单个），或拖拽到此
          </template>
          <template v-else-if="fileStore.selectedFunction === 'merge_excel_files'">
            上传要合并的 Excel 文件（多个），或拖拽到此
          </template>
          <template v-else>
            拖拽文件到此，或
            <em>点击上传</em>
          </template>
        </div>
        <div class="upload-tip">
          <template
            v-if="
              fileStore.selectedFunction === 'split_by_header' ||
              fileStore.selectedFunction === 'split_by_header_enhanced'
            "
          >
            将按指定表头拆分为多个文件或Sheet
          </template>
          <template v-else-if="fileStore.selectedFunction === 'sample_meter_list'">
            将按指定表头和值随机抽取记录
          </template>
          <template v-else-if="fileStore.selectedFunction === 'sample_data'">
            将按指定条件进行数据抽样
          </template>
          <template v-else-if="fileStore.selectedFunction === 'budget_calculation'">
            将根据模板生成预算文件
          </template>
          <template v-else-if="fileStore.selectedFunction === 'merge_excel_files'">
            将多个Excel文件合并为一个文件
          </template>
          <template v-else>支持多文件上传，仅支持 Excel 文件</template>
        </div>
      </div>
    </el-upload>
  </div>
</template>

<style scoped>
:deep() {
  .el-upload-list {
    max-height: 200px;
    overflow-y: auto;
  }
}

.upload-area {
  margin: 20px 0;
}

.upload-dragger {
  width: 100%;
  border-radius: 10px;
  transition: all 0.3s ease;
}

.upload-content {
  padding: 40px 20px;
  text-align: center;
}

.upload-icon {
  font-size: 60px;
  color: #c0c4cc;
  margin-bottom: 20px;
  transition: all 0.3s ease;
}

.upload-dragger:hover .upload-icon {
  color: #409eff;
  transform: scale(1.1);
}

.upload-text {
  font-size: 18px;
  color: #606266;
  margin-bottom: 12px;
}

.upload-text em {
  color: #409eff;
  font-style: normal;
  font-weight: bold;
}

.upload-tip {
  font-size: 14px;
  color: #909399;
}
</style>
